package com.sunplus.common.core.ossstorage;

import com.sunplus.common.core.ossstorage.aliyunstorage.AliyunOssProvicer;
import com.sunplus.common.core.ossstorage.inteface.IStorageProvider;
import com.sunplus.common.utils.file.FileTypeUtils;

import java.io.InputStream;

/**
 * 文件上传客户端(对外使用的接口)
 *
 * @author shaoqi
 * @date 下午 2:51 2021/2/7 0007
 */

public class UploadClient {

    //要使用单例模式 重复进行创建

    private static UploadClient instance = new UploadClient();

    private IStorageProvider storageProvider;

    public static UploadClient getInstance() {
        return instance;
    }

    public UploadClient() {
        String endPoint = "";
        String keyId = "";
        String keySecret = "";
        String bucketName = "";

        storageProvider = new AliyunOssProvicer(endPoint, keyId, keySecret, bucketName);
    }

    /**
     * 上传文件
     * @param stream 文件流
     * @param fileName 文件名字(主要用于获取文件后缀)
     * @return
     */
    public String pLoadProcess(InputStream stream, String fileName) {
        return upLoadProcess(stream, fileName, "");
    }


    /**
     * 上传文件
     * @param stream 文件流
     * @param fileName 文件名称(主要用于获取文件后缀)
     * @param rename 文件重命名
     * @return
     */
    public String upLoadProcess(InputStream stream, String fileName, String rename) {
        return "";
    }



    public String UpLoad(InputStream stream, String rename, String path, String fileName) {
        String savePath = "";

     /*   if (String.IsNullOrWhiteSpace(rename))
        {
            savePath = path + "/" + Guid.NewGuid() + FileTypeUtils.getFileType(fileName);
        }
        else
        {
            savePath = path + "/" + rename + System.IO.Path.GetExtension(fileName);
        }
    */

        storageProvider.saveStream(savePath, stream);
        return savePath;
    }

}
